package com.hqyj.freemovie.front.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hqyj.freemovie.front.domain.Roles;
import com.hqyj.freemovie.front.domain.UsersRoles;
import com.hqyj.freemovie.front.mapper.UsersRolesMapper;
import com.hqyj.freemovie.front.service.RolesService;
import com.hqyj.freemovie.front.service.UsersRolesService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class UsersRolesServiceImpl extends ServiceImpl<UsersRolesMapper, UsersRoles> implements UsersRolesService {

    @Resource
    private RolesService rolesService;
    @Override
    public List<Roles> queryUsersRolesByUid(Integer uid) {
        //等会做...

        QueryWrapper<UsersRoles> queryWrapper  = new QueryWrapper<UsersRoles>();
        queryWrapper.eq("uid",uid);
        List<Roles> rolesList = new ArrayList<Roles>();
        List<UsersRoles> usersRolesList = super.list(queryWrapper);
        if(usersRolesList!=null&& usersRolesList.size()>0){
            for(UsersRoles usersRoles : usersRolesList){
                Roles r =  rolesService.getById(usersRoles.getRid());
                rolesList.add(r);
            }
        }
        return rolesList;
    }
}
